package com.waylau.spring.boot.blog.repository;

import com.waylau.spring.boot.blog.domain.Forget;
import com.waylau.spring.boot.blog.domain.Genre;
import com.waylau.spring.boot.blog.domain.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Collection;
import java.util.List;

/**
 * Authority 仓库.
 *
 * @since 1.0.0 2017年3月2日
 * @author <a href="https://waylau.com">Way Lau</a> 
 */
public interface GenreRepository extends JpaRepository<Genre, Long>{


    /**
     * 获取指定Genre
     * @param name
     * @return
     */
    Genre findByName(String name);


    /**
     * 获取指定状态的Genres
     * @param status
     * @return
     */
    List<Genre> findByStatus(Integer status);

    /**
     * 分页
     * 获取指定状态的Genres
     * @param status
     * @return
     */
    Page<Genre> findByStatus(Integer status, Pageable pageable);

    /**
     * 随机取出几条数据
     * @param num
     * @return
     */
    @Query(value = "select * from genre order by rand() limit ?1",nativeQuery = true)
    List<Genre> random(Integer num);

    /**
     * 随机取出几条数据
     * @param num
     * @return
     */
    @Query(value = "select * from genre where id not in (?1) order by rand() limit ?2",nativeQuery = true)
    List<Genre> randomAndIdsNotIn(Collection c, Integer num);

    /**
     *
     * @param name
     * @param i
     * @param pageable
     * @return
     */
    Page<Genre> findByNameLikeAndStatus(String name, int i, Pageable pageable);
}
